#pragma once

#include "InetAddr.hpp"
#include "Socket.hpp"
#include "TcpServer.hpp"
#include "Util.hpp"
#include "Log.hpp"
#include <cstdint>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>

using namespace LogModule;
using namespace SocketModule;

const std::string gsp = " ";
const std::string glinespacee = "\r\n";

class HttpRequest {
public:
    HttpRequest() {}
    std::string Serialize() {
        return std::string();
    }
    bool Deserialisze(std::string str) {
        return true;
    }
    ~HttpRequest() {}
private:
    std::string _method;
    std::string _url;
    std::string _version;
    std::unordered_map<std::string, std::string> _header;
    std::string _blankline;
    std::string _text;
};

class Http {
public:
    Http(uint16_t port) : ts(std::make_unique<TcpServer>(port)) {
    }
    void HandlerHttpRequset(std::shared_ptr<Socket>& sock, InetAddr& client) {
        #ifndef DEBUG
        #define DEBUG
                std::string httpstr;
                sock->Recv(&httpstr);
                std::cout << httpstr;
        #endif
    }
    void Start() {
        ts->Start([this](std::shared_ptr<Socket> &sock, InetAddr& client) {
            this->HandlerHttpRequset(sock, client);
        });
    }
    ~Http() {
        
    }
private:
    std::unique_ptr<TcpServer> ts;
};
